//
//  GB_LeftViewController.m
//  MELive
//
//  Created by 郭宝 on 16/10/20.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "GB_LeftViewController.h"
#import "Macro.h"
#import "GB_LeftTableViewCell.h"
#import "GB_SettingViewController.h"
#import "GB_HelpViewController.h"
#import "SDImageCache.h"
@interface GB_LeftViewController () <UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, strong) UIButton *loginBackButton;
@property (nonatomic, strong) UIButton *settingButton;

@end

@implementation GB_LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
    self.navigationController.navigationBar.hidden = YES;
    [self creatButton];
}

- (void)createView {
    _tableView.tableHeaderView = _headView;
    _headView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 233);
    _headView.backgroundColor = [UIColor whiteColor];
    [_tableView registerNib:[UINib nibWithNibName:@"GB_LeftTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GB_LeftTableViewCell"];
    _array = @[@"认识的人", @"新秀主播", @"清理缓存", @"帮助", @"意见反馈", @"关于我们"];
}
- (void)creatButton {
    _settingButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _settingButton.frame = CGRectMake(SCREEN_WIDTH - 40, 30, 20, 20);
    [_settingButton setImage:[[UIImage imageNamed:@"settingicon50px"] imageWithRenderingMode:1] forState:UIControlStateNormal];
//    _settingButton.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_settingButton];
    [_settingButton addTarget:self action:@selector(didSettionAction:) forControlEvents:UIControlEventTouchUpInside];
    _loginBackButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _loginBackButton.backgroundColor = [UIColor blueColor];
    _loginBackButton.frame = CGRectMake(20, 30, 20, 20);
    [self.view addSubview:_loginBackButton];
    [_loginBackButton setImage:[[UIImage imageNamed:@"loginBack50px"] imageWithRenderingMode:1] forState:UIControlStateNormal
     ];
    [_loginBackButton addTarget:self action:@selector(didBackAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)didSettionAction:(UIButton *)button {
    GB_SettingViewController *VC = [[GB_SettingViewController alloc] initWithNibName:@"GB_SettingViewController" bundle:[NSBundle mainBundle]];
    self.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController pushViewController:VC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}
- (void)didBackAction:(UIButton *)button {
    self.navigationController.navigationBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];

}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GB_LeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GB_LeftTableViewCell" forIndexPath:indexPath];
    cell.columnLabel.text = _array[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        
    } else if (indexPath.row == 1) {
        
    } else if (indexPath.row == 2) {
        float tmpSize = [[SDImageCache sharedImageCache] getSize];
        [[SDImageCache sharedImageCache] clearDisk];
        NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize/1000000] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize/1000];
        NSLog(@"%@",clearCacheName);
    } else if (indexPath.row == 3) {
        GB_HelpViewController *vc = [GB_HelpViewController new];
        vc.itemTitle = _array[indexPath.row];
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 4) {
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
